
package com.viweb.storemanager.core;

import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;


public class ButtonCellRenderer extends JButton implements TableCellRenderer {

    private ImageIcon imageIcon;

    public ButtonCellRenderer(ImageIcon imageIcon) {
        super();
        this.imageIcon = imageIcon;
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (this.imageIcon == null) {
            this.setText(value.toString());
        } else {
            this.setIcon(this.imageIcon);
            this.setToolTipText(this.imageIcon.getDescription());
        }

        return this;
    }
}
